home *** CD-ROM | disk | FTP | other *** search
- /*
- * Initialization segment for INTERNAT
- * This code is discarded after it is used.
- *
- * William S. Hall
- * 3665 Benton Street, #66
- * Santa Clara, CA 95051
- *
- */
-
- #define NOKANJI
- #define NOCOMM
- #define NOWH
- #define NOATOM
- #include <windows.h>
- #include <string.h>
- #include "internat.h"
- #include "interstr.h"
- #include "interint.h"
- #include "winutils.h"
- #include "intdgdef.h"
-
- /* local function declarations */
- static BOOL NEAR RegisterWindowClass(HANDLE);
- static void NEAR GetPrevInstanceData(HANDLE);
- static HWND NEAR MakeAndShowMainWnd(HANDLE, int);
- static HANDLE NEAR GetLanguageResource(void);
-
- /* This routine is FAR since it is called from another segment */
- BOOL FAR InitProgram(HANDLE hInstance, HANDLE hPrevInstance,
- LPSTR lpszCmdLine, int cmdShow)
- {
- hInst = hInstance;
-
- /* failed to get a language resource so take the default language */
- if ((hRC = GetLanguageResource()) < 32)
- hRC = hInstance;
-
- /* if this is the first instance of the program ... */
- if (!hPrevInstance) {
- /* register the window */
- if (!RegisterWindowClass(hInstance))
- return FALSE;
- }
-
- /* A previous instance already exists so get global data from there */
- else
- GetPrevInstanceData(hPrevInstance);
-
- /* Create and show the window */
- if (!MakeAndShowMainWnd(hInstance, cmdShow))
- return FALSE;
-
- return TRUE;
- }
-
- /* Every window must belong to a class. We register ours here */
- static BOOL NEAR RegisterWindowClass(HANDLE hInstance)
- {
-
- WNDCLASS WndClass;
-
- LoadString(hRC, IDS_APPNAME,(LPSTR)szAppName,sizeof(szAppName));
- memset(&WndClass, 0, sizeof(WndClass));
-
- WndClass.hCursor = LoadCursor(NULL, IDC_ARROW); /* standard cursor */
- WndClass.hIcon = LoadIcon(hRC, szAppName); /* no icon */
- WndClass.lpszMenuName = (LPSTR)szAppName;
- WndClass.lpszClassName = (LPSTR)szAppName; /* our class name */
- WndClass.hbrBackground = COLOR_WINDOW + 1; /* system color */
- WndClass.hInstance = hInstance; /* instance handle */
- WndClass.style = CS_VREDRAW | CS_HREDRAW; /* standard redraw values */
- WndClass.lpfnWndProc = MainWndProc; /* pointer to our window proc */
-
- return (RegisterClass(&WndClass));
-
- }
-
- /*
- If this not the first instance, we can retrieve static data from a
- previous invocation of the program
- */
- static void NEAR GetPrevInstanceData(HANDLE hPrevInstance)
- {
-
- GetInstanceData(hPrevInstance, (PSTR)szAppName, sizeof(szAppName));
-
- }
-
- /*
- Create the window, making sure that its position and size are suitable
- for the display.
- */
- static HWND NEAR MakeAndShowMainWnd(HANDLE hInstance, int cmdShow)
- {
-
- char szTitle[50];
-
- LoadString(hRC, IDS_TITLE, szTitle, sizeof(szTitle));
-
- /* Create the window, letting it fall where Windows wants.
- Also, load the menu now since the resource handle may have changed */
-
- hWndMain = CreateWindow((LPSTR)szAppName,
- (LPSTR)szTitle,
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT,0,
- CW_USEDEFAULT,0,
- (HWND)NULL,
- (HMENU)LoadMenu(hRC, szAppName),
- (HANDLE)hInstance,
- (LPSTR)NULL);
-
- /* if we succeed, show the window */
- if (hWndMain) {
- ShowWindow(hWndMain, cmdShow);
- UpdateWindow(hWndMain);
- }
- return hWndMain;
- }
-
- /* initialize the display buffer and read some font parameters */
- void FAR WndCreate(HWND hWnd)
- {
- HDC hDC;
- TEXTMETRIC tm;
- register int i;
-
- hDC = GetDC(hWnd);
- SelectObject(hDC, GetStockObject(SYSTEM_FIXED_FONT));
- GetTextMetrics(hDC, &tm);
- cwidth = tm.tmAveCharWidth;
- /* adjust row spacing by 6/5 */
- cheight = MulDiv(6, tm.tmHeight + tm.tmExternalLeading, 5);
- /* use this parameter for the rectangle where the key stuff is shown */
- kwidth = cwidth * (32 + 3);
- ReleaseDC(hWnd, hDC);
-
- /* load the backing storage buffer */
- for (i = 0; i < sizeof(display); i++)
- display[i] = (BYTE)i;
-
- }
-
- /* Show the language choices and respond accordingly */
- static HANDLE NEAR GetLanguageResource(void)
- {
- int result;
- HANDLE h = hInst;
- BYTE buf[80];
- FARPROC fp;
-
- fp = MakeProcInstance(LangDlgFunc, hInst);
- result = DialogBox(hInst, MAKEINTRESOURCE(DT_LANGUAGE), NULL, fp);
- FreeProcInstance(fp);
-
- switch(result) {
- case IDS_PIGLATIN:
- LoadString(hInst, IDS_PGLLIBNAME, buf, sizeof(buf));
- h = LoadLibrary(buf);
- break;
- }
- return h;
- }
-